package com.jiunuan.live.api.controller;

import com.jiunuan.live.api.service.IHomePageService;
import com.jiunuan.live.api.vo.HomePageVO;
import com.jiunuan.live.common.interfaces.vo.WebResponseVO;
import com.jiunuan.live.web.starter.context.JiuNuanRequestContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/home")
@Tag(name = "Home-首页相关接口")
public class HomePageController {
    @Resource
    private IHomePageService homePageService;
    @Operation(summary = "initPage-初始化首页")
    @PostMapping("/initPage")
    public WebResponseVO initPage() {
        Long userId = JiuNuanRequestContext.getUserId();
        HomePageVO homePageVO = new HomePageVO();
        homePageVO.setLoginStatus(false);
        if (userId != null) {
            homePageVO = homePageService.initPage(userId);
            homePageVO.setLoginStatus(true);
        }
        // 前端调用initPage--->success状态，代表登录过了，token依旧有效
        return WebResponseVO.success(homePageVO);
    }
}
